package com.red.basic.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.red.basic.domain.RedCustomFolder;
import com.red.basic.dto.RedCustomDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.red.common.annotation.Log;
import com.red.common.core.controller.BaseController;
import com.red.common.core.domain.AjaxResult;
import com.red.common.enums.BusinessType;
import com.red.basic.domain.RedCustom;
import com.red.basic.service.IRedCustomService;
import com.red.common.utils.poi.ExcelUtil;
import com.red.common.core.page.TableDataInfo;

/**
 * 客户管理Controller
 * 
 * @author bug2222
 * @date 2024-11-09
 */
@RestController
@RequestMapping("/basic/custom")
public class RedCustomController extends BaseController
{
    @Autowired
    private IRedCustomService redCustomService;

    @PreAuthorize("@ss.hasPermi('basic:custom:list')")
    @GetMapping("/customFolder")
    public AjaxResult list()
    {
        List<RedCustomFolder> list = redCustomService.getCustomFolder();
        return success(list);
    }

    /**
     * 查询客户管理列表
     */
    @PreAuthorize("@ss.hasPermi('basic:custom:list')")
    @GetMapping("/list")
    public TableDataInfo list(RedCustomDto redCustom)
    {
        startPage();
        List<RedCustomDto> list = redCustomService.selectRedCustomList(redCustom);
        return getDataTable(list);
    }

    /**
     * 导出客户管理列表
     */
    @PreAuthorize("@ss.hasPermi('basic:custom:export')")
    @Log(title = "客户管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RedCustomDto redCustom)
    {
        List<RedCustomDto> list = redCustomService.selectRedCustomList(redCustom);
        ExcelUtil<RedCustomDto> util = new ExcelUtil<RedCustomDto>(RedCustomDto.class);
        util.exportExcel(response, list, "客户管理数据");
    }

    /**
     * 获取客户管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:custom:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(redCustomService.selectRedCustomById(id));
    }

    /**
     * 新增客户管理
     */
    @PreAuthorize("@ss.hasPermi('basic:custom:add')")
    @Log(title = "客户管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RedCustomDto redCustom)
    {
        return toAjax(redCustomService.insertRedCustom(redCustom));
    }

    /**
     * 修改客户管理
     */
    @PreAuthorize("@ss.hasPermi('basic:custom:edit')")
    @Log(title = "客户管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RedCustomDto redCustom)
    {
        return toAjax(redCustomService.updateRedCustom(redCustom));
    }

    /**
     * 删除客户管理
     */
    @PreAuthorize("@ss.hasPermi('basic:custom:remove')")
    @Log(title = "客户管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(redCustomService.deleteRedCustomByIds(ids));
    }
}
